package com.config;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

@Configuration
public class LocaleConfig implements LocaleResolver{

	public Locale resolveLocale(HttpServletRequest request) {
		String L=request.getParameter("L");
		if(!StringUtils.isEmpty(L)) {
			String [] part=L.split("_");
			Locale cale=new Locale(part[0],part[1]);
			return cale;
		}
		return Locale.getDefault();
	}

	public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {}
	
	@Bean
	public LocaleResolver LocaleResolver() {
		return this;
	}
}
